/*
 * GameWorld.cpp
 *
 *  Created on: Jan 4, 2009
 *      Author: Carmine Red
 */

#include "GameWorld.h"

#include <assert.h>		// for assert

bool tester = false;

GameWorld::GameWorld()
{
	dirTileArray = 0;
	entranceTile.setIsEntrance(true);
	entranceSet = false;

	//test
	test.setDir(RIGHT);

	////////////////////////////////////////////////////
	// Test enemy
	////////////////////////////////////////////////////

    //create a new enemy
    Enemy newEnemy;

    newEnemy.setDir(DOWN);
    newEnemy.setSpeed(1);
    newEnemy.setxPos(0);
    newEnemy.setyPos(0);

    //add to list
    listEnemies.push_back(newEnemy);
}

GameWorld::~GameWorld()
{
	if(dirTileArray != 0)
	{
		for(int i = 0; i < rows; ++i)
		{
			delete [] dirTileArray[i];
		}
		delete [] dirTileArray;
	}

	if(collisionArray != 0)
	{
		for(int i = 0; i < rows; ++i)
		{
			delete [] collisionArray[i];
		}
		delete [] collisionArray;
	}

	// clear listEnemies
	std::list<Enemy>::iterator i = listEnemies.begin();
	while(i != listEnemies.end())
			i->cleanUp();

	listEnemies.clear();

	// clear listFences
	std::list<LightFence>::iterator j = listFences.begin();
	while(j != listFences.end())
			j->cleanUp();

	listFences.clear();

	// clear listAnchor
	std::list<AnchorPoint>::iterator k = listAnchor.begin();
	while(k != listAnchor.end())
			k->cleanUp();

	listAnchor.clear();

}

bool GameWorld::loadLevel()	// loads a new level into the world, will take input later
{
	// reset entrance tile
	entranceTile.setIsEntrance(true);
	entranceTile.setDir(NODIRECTION);
	entranceTile.setxPos(0);
	entranceTile.setyPos(0);

	// placeholder test data
	//	INTEND TO LOAD SIMPLE LEVEL DATA FROM FILE
	rows = 4;
	cols = 4;

	//construct the level's properties according to RowCol data

	levelWidth = rows * DIRTILESIDE;
	levelHeight = cols * DIRTILESIDE;

	// create the sectors

	dirTileArray = new DirTile* [rows];
	for(int i = 0; i < rows; ++i)
	{
		dirTileArray[i] = new DirTile[cols];
	}

	// create the collision array

	collisionArray = new bool* [rows];
	for(int i = 0; i < rows; ++i)
	{
		collisionArray[i] = new bool[cols];
	}

	// take the time to give each sector its xPos and yPos

	for(int i = 0; i < rows; ++i)
	{
		for(int j = 0; j < cols; ++j)
		{
			dirTileArray[i][j].setxPos((0.5 + (float)j) * DIRTILESIDE - (levelWidth * 0.5));
			dirTileArray[i][j].setyPos((-0.5 + (rows - (float)i)) * DIRTILESIDE - (levelHeight * 0.5));
		}
	}

	/*
	NOTE: STILL NOT SURE ABOUT THIS PLACEMENT ALGORITHM, NOT CONCRETE KNOWLEDGE OF IF ITS CORRECT

	BRAIN EXERCISE TIME!!!

	if the width is 40 and height is 40...

	it's easy to get a sector's x and y displacement from the
	upper left origin of the 2d array:

	Sector.xPos = (0.5 + secCol) * SECTORSIDE;
	Sector.yPos = (0.5 + secRow) * SECTORSIDE;

	but what if the origin is the center of the level?
	in this case 0,0 is situated at 20,20

	centerxOffset = 20;

	and don't forget the y flip!

	Sector.newxPos = (0.5 + secRow) * SECTORSIDE - centerxOffset;
	Sector.newyPos = (-0.5 + (sectorRows - secRow)) * SECTORSIDE - centerYoffset;

	*/

	return true;	// should return false if load fails
}

void GameWorld::update(Prismatic* game)		// this update handles a lot of stuff
{
	// set any previews

	// get cursor location
	float CursorX = game->mouseXCoord();
	float CursorY = game->mouseYCoord();

	int xInd = -1;
	int yInd = -1;


	// use cursor location for preview data
	if(getRelevantTile(CursorX, CursorY, xInd, yInd))
	{
		assert(xInd != -1);
		assert(yInd != -1);
		//toUse->renderPreview(game);
		//toUse->render(game);
		//toUse->setIsMousedOver(true);
		dirTileArray[yInd][xInd].setIsMousedOver(true);
	}

	////////////////////// TEMP ENEMY HOLDING ////////////////

	// eventually we'll want to handle removing enemies that escape

	test.moveEnemy();

	if(isOutOfLevel(test.getxPos(), test.getyPos()) != false)
	{
		if(entranceSet == true)
		{
			test.setxPos(entranceTile.getxPos());
			test.setyPos(entranceTile.getyPos());
			test.setDir(entranceTile.getDir());
		}
		else
		{
			test.setxPos(dirTileArray[0][0].getxPos());
			test.setyPos(dirTileArray[0][0].getyPos() + ENTRANCETILEOFFSET);
			test.setDir(DOWN);
		}



		/*
		switch(test.getDir())
		{
		case UP:
			test.setDir(RIGHT);
			break;
		case RIGHT:
			test.setDir(UP);	// test to see my two directions
			break;
		case DOWN:
			test.setDir(LEFT);
			break;
		case LEFT:
			test.setDir(UP);
			break;
		default:
			test.setDir(UP);
		}
		*/
	}

	////////////////////// TEMP ENEMY HOLDING ////////////////

	// move enemies and check if they've escaped


	/*
	std::list<Enemy>::iterator i = listEnemies.begin();
	while(i != listEnemies.end())
	{
		// do stuff
		i->moveEnemy();
		// need to check if enemy is out of level
		////////////////////////////////////
		if(isOutOfLevel(i->getxPos(), i->getyPos()))
		{
			//remove enemy
			i = listEnemies.erase(i);

			////////////////////

			// do whatever update is required when an enemy escapes

			////////////////////
		}
		else
		{
			++i;
		}
	}
	*/

	// check enemies against tiles

	// using test

	xInd = -1;
	yInd = -1;

	if(getRelevantTile(test.getxPos(), test.getyPos(), xInd, yInd))
	{
		// if this found a tile...
		if(dirTileArray[yInd][xInd].getIsSet() == true)
		{
			test.checkTile(dirTileArray[yInd][xInd].getxPos(),
							dirTileArray[yInd][xInd].getyPos(),
							dirTileArray[yInd][xInd].getDir()
							);
		}
	}

	/*
	DirTile* relevantTile;

	i = listEnemies.begin();
	while(i != listEnemies.end())
	{
		if(getRelevantTile(relevantTile, i->getyPos(), i->getyPos()))
		{
			// if this enemy IS on a relevant tile update the enemy based on that tile
			i->checkTile(relevantTile->getxPos(), relevantTile->getyPos(), relevantTile->getDir());
		}
		++i;
	}
	*/

	////////////////////////////////////////////////////////
	// check light fences against enemies
	////////////////////////////////////////////////////////

	/*
	NOTE:
	This is how we'll go through comparing the game characters (enemies) to the light
	fences: first we'll check if the light fence is active.

	If one is, then we'll run through each game character and check if it is within
	range of the fence.

	If it is, then we'll set/update their status with regards to whether they're above
	or below the fence. There are two conditions possible: above or below.

	THIS STATUS INFO WILL BE KEPT ON THE LIGHTFENCE, NOT THE ENEMY.

	IF the checkAttack property is false (meaning the fence was previously inactive),
	then we set it to active and we'd normally be done with the checking process.
		OTHERWISE we're allowed to check if there were any changes. We'll cycle through
			the changes.
			IF there were thing that crossed, we then choose the target(s), deal the
			damage, set the cooldown to start counting down again, and erase our enemy
			status memory.
	*/

	// this tracks if an nme status switched
	bool changeHappen;

	// this is used if we need to choose between enemies
	int attackNum;

	// this is used to check if only one enemy triggered so we don't have to keep counting
	int singleCheck;

	/*
	std::list<LightFence>::iterator j = listFences.begin();
	while(j != listFences.end())
	{
		if(j->isActive())
		{
			changeHappen = false;	// reset to false for each fence

			i = listEnemies.begin();
			while(i != listEnemies.end())
			{
				if(j->isInRange(i->getxPos(), i->getyPos()))
				{
					if(j->nmeRec.isInStruct(i->getID()) == false)
					{
						// add enemy to fence enemy status structure
						j->nmeRec.addRecordnme(i->getID());
					}
					else
					{
						// this enemy is eligible for checking status
						if(j->isAbove(i->getxPos(), i->getyPos()) != j->nmeRec.getnmeAboveStatus(i->getID()))
						{
							// the enemy status has changed
							j->nmeRec.setnmeChanged(i->getID(), true);
							changeHappen = true;
						}
						else
						{
							j->nmeRec.setnmeChanged(i->getID(), false);
						}
					}
					j->nmeRec.setnmeAboveStatus(i->getID(), j->isAbove(i->getxPos(), i->getyPos()));
				}
				else
				{
					// we may need to remove the enemy from the fence's records
					if(j->nmeRec.isInStruct(i->getID()) == true)
					{
						j->nmeRec.removeViaID(i->getID());
					}
				}
				++i;
			}

			if(j->getcheckAttack() && changeHappen)
			{
				// choosing from an eligible crossing enemy at random

				attackNum = (rand() % 20) + 1;
				singleCheck = attackNum;
				while(attackNum > 0)
				{
					for(int count = j->nmeRec.getNumEnemies(); count >= 0; ++count)
					{
						if(j->nmeRec.getnmeChangedViaIndex(count) == true)
						{
							if(attackNum == 0)
							{
								j->triggerDamage();
								i->applyDamage(j->getmyDamage());
								break;
							}
							else if(singleCheck == -1)
							{
								j->triggerDamage();
								i->applyDamage(j->getmyDamage());
								break;
							}
							else
							{
								--attackNum;
							}
						}
					}

					if(attackNum + 1 == singleCheck)
					{
						// we only found one enemy! let's not waste time iterating more!
						// set the singleCheck sentinel to -1 to catch it next time!
						singleCheck = -1;
					}
				}
			}
		}
		++j;
	}
	*/


	/*
	 * bool changeHappen;	// this tracks if an nme status switched
	 * int attackNum;		// this is used if we need to choose between enemies
	 *
	 * FOR ALL FENCES
	 * {
	 * 		IF(FENCE->isActive())
	 * 		{
	 * 			changeHappen = false;	// reset to false for each fence
	 *
	 * 			FOR ALL ENEMIES
	 * 			{
	 * 				IF(FENCE->isInRange(enemy->xLoc, enemy->yLoc))
	 * 				{
	 * 					IF(FENCE->nmeRec.isInStruct(enemy->id) == false)
	 * 					{
	 * 						// add enemy to fence enemy status structure
	 * 						FENCE->nmeRec.addRecordnme(enemy->id);
	 * 					}
	 * 					else
	 * 					{
	 * 						// this enemy is eligible for checking status
	 * 						if(fence->isAbove(enemy->xLoc, enemy->yLoc) != FENCE->nmeRec.getnmeAboveStatus(enemy->id))
	 *	 					{
	 * 							// the enemy status has changed
	 * 							FENCE->nmeRec.setnmeChanged(enemy->id, true);
	 * 							changeHappen = true;
	 * 						}
	 * 						else
	 *						{
	 *							FENCE->nmeRec.setnmeChanged(enemy->id, false);
	 *						}
	 * 					}
	 *
	 * 					FENCE->nmeRec->setEnemyStat(enemyID, fence->isAbove());
	 * 				}
	 * 				else
	 * 				{
	 * 					// we may need to remove the enemy from the fence's records
	 * 					if(FENCE->nmeRec.isInStruct(enemy->id) == true)
	 * 					{
	 * 						FENCE->nmeRec.removeViaID(enemy->id);
	 * 					}
	 * 				}
	 * 			}
	 *
	 * 			IF(FENCE->checkAttack() && changeHappen)
	 * 			{
	 *				attackNum = rand() % 20 + 1;
	 *				FOR EACH ENEMY IN FENCE->nmeRec USING INDEX
	 *				{
	 *					IF(FENCE->nmeRec.getnmeChangedViaIndex(INDEX) == true)
	 *					{
	 *						if(attackNum==0)
	 *						{
	 *							FENCE->doDamage(FENCE->nmeRec.getnmeID(INDEX));
	 *							break;
	 *						}
	 *						else
	 *						{
	 *							--attackNum;
	 *						}
	 *					}
	 *				}
	 * 			}
	 * 		}
	 * }
	 */

	/*
	 * Here I am going to go through the process of checking each light fence
	 * against all the enemies for possible damage stuff
	 * ~Cai 1/3/2008
	 */
}

void GameWorld::render(Prismatic* game)
{
	// note: if level has not started yet, then use preview for entranceTile rendering
	// note: use preview for any Directional Tiles considering user activation, but not yet activated

	// render each of our elements

	// render each tile on the level
	for(int i = 0; i < rows; ++i)
	{
		for(int j = 0; j < cols; ++j)
		{
			dirTileArray[i][j].render(game);
		}
	}

	// render entrance tile
	entranceTile.render(game);

	// this test enemy starts at center of screen
	test.render(game);

	// testing
	if(tester)
	{
		//test.render(game);
		tester = false;
	}

}

bool GameWorld::getRelevantTile(float xUse, float yUse, int &xInd, int &yInd)
// returns the indices
// to the DirTile being pointed at
{
	// start at upper left

	float upperLeftx = (dirTileArray[0][0].getxPos() - 0.5 * DIRTILESIDE);
	float upperLefty = (dirTileArray[0][0].getyPos() + 0.5 * DIRTILESIDE);

	/*
	 * BRAIN TIME!!!
	 *
	 * 	To return the sector, we need to find the row and col indices for where
	 * our mouse is.
	 *
	 * 	Of course, first we should check to see if the mouse is out of bounds of the rows.
	 *
	 * 	Then, we start with the x and increment right by DIRTILESIDE until we catch the xMouse.
	 *	We do the same for y. This gives us the indices. We return the indices...
	 */

	if(xUse < upperLeftx ||
		yUse >= upperLefty ||
		xUse >= (upperLeftx + cols * DIRTILESIDE) ||
		yUse < (upperLefty - rows * DIRTILESIDE))
	{
		// out of bounds
		return false;
	}
	else
	{
		int xIndex = -1;
		int yIndex = -1;

		int i = 0;

		while(i < cols && xIndex == -1)
		{
			upperLeftx += DIRTILESIDE;
			if(xUse < upperLeftx)
			{
				// we've found the column
				xIndex = i;
			}
			++i;
		}

		i = 0;

		while(i < rows && yIndex == -1)
		{
			upperLefty -= DIRTILESIDE;
			if(yUse > upperLefty)
			{
				// we've found the row
				yIndex = i;
			}
			++i;
		}

		if(xIndex == -1 || yIndex == -1)
		{
			// didn't find it
			return false;
			////////////////////////////////
			// AAAHHHH WE'RE IN TROUBLE IF WE GET HERE!!!!
			////////////////////////////////
		}
		else
		{
			if(xIndex < cols && yIndex < rows)
			{
				tester = true;
				xInd = xIndex;
				yInd = yIndex;
				return true;
			}
			else
			{
				return false;
			}
		}
	}

	return false;
}

// not tested this yet
void GameWorld::setEntranceTile(float xUse, float yUse)	// sets entranceTile info
{
	///////////////
	// DETERMINE CLOSEST REGULAR TILE
	///////////////

	int xIndex = cols - 1;

	float upperLeftx = -1.0 * (levelWidth * 0.5);
	float upperLefty = (levelHeight * 0.5);

	for(int i = 0; i < cols; ++i)
	{
		upperLeftx += DIRTILESIDE;
		if(xUse < upperLeftx)
		{
			// we've found the column
			xIndex = i;
			break;
		}
	}

	int yIndex = rows - 1;

	for(int i = 0; i < rows; ++i)
	{
		upperLefty -= DIRTILESIDE;
		if(yUse >= upperLefty)
		{
			// we've found the row
			yIndex = i;
			break;
		}
	}

	// set first tile data
	firstTileX = xIndex;
	firstTileY = yIndex;

	// testing

	//entranceTile.setxPos(dirTileArray[yIndex][xIndex].getxPos());
	//entranceTile.setyPos(dirTileArray[yIndex][xIndex].getyPos());
	//entranceTile.setIsSet(true);
	//entranceTile.setDir(UP);

	///////////////
	// DETERMINE DIRECTION
	///////////////

	// when determining direction on corners, the value that differs the
	// least with the typical tile values "wins"

	// reset the upperLeft coordinates
	//upperLeftx = 0.5 * DIRTILESIDE - (levelWidth * 0.5);
	//upperLefty = (-0.5 + rows) * DIRTILESIDE - (levelHeight * 0.5);
	upperLeftx = -1.0 * (levelWidth * 0.5) + DIRTILESIDE;
	upperLefty = (levelHeight * 0.5) - DIRTILESIDE;



	if(xIndex == 0 && yIndex == 0)
	{
		// need to determine upper left corner
		if(	upperLeftx - xUse
				<
			yUse - upperLefty)
		{
			// x is dominant
			entranceTile.setDir(DOWN);
		}
		else
		{
			// y is dominant
			entranceTile.setDir(RIGHT);
		}
	}
	else if(xIndex == (cols - 1) && yIndex == 0)
	{
		// need to determine upper right corner
		if(	xUse - (upperLeftx + ((cols - 2) * DIRTILESIDE))
				<
			yUse - upperLefty)
		{
			// x is dominant
			entranceTile.setDir(DOWN);
		}
		else
		{
			// y is dominant
			entranceTile.setDir(LEFT);
		}
	}
	else if(xIndex == 0 && yIndex == (rows - 1))
	{
		// need to determine lower left corner
		if(	upperLeftx - xUse
				<
			(upperLefty - ((rows - 2) * DIRTILESIDE)) - yUse)
		{
			// x is dominant
			entranceTile.setDir(UP);
		}
		else
		{
			// y is dominant
			entranceTile.setDir(RIGHT);
		}
	}
	else if(xIndex == (cols - 1) && yIndex == (rows - 1))
	{
		// need to determine lower right corner
		if(	xUse - (upperLeftx + ((cols - 2) * DIRTILESIDE))
				<
				(upperLefty - ((rows - 2) * DIRTILESIDE)) - yUse)
		{
			// x is dominant
			entranceTile.setDir(UP);
		}
		else
		{
			// y is dominant
			entranceTile.setDir(LEFT);
		}
	}
	else
	{
		// determine direction via dominant row
		if(xIndex == 0 || xIndex == cols - 1)
		{
			entranceTile.setDir(LEFT);
			if(xIndex == 0)
			{
				entranceTile.setDir(RIGHT);
			}
		}
		else
		{
			entranceTile.setDir(UP);
			if(yIndex == 0)
			{
				entranceTile.setDir(DOWN);
			}
		}
	}

	assert(entranceTile.getDir() != NODIRECTION);	// by now a direction should be set

	///////////////
	// DETERMINE ENTRANCE TILE X AND Y
	///////////////

	entranceTile.setxPos(dirTileArray[yIndex][xIndex].getxPos());
	entranceTile.setyPos(dirTileArray[yIndex][xIndex].getyPos());

	// adjust according to direction
	switch(entranceTile.getDir())
	{
	case UP:
		entranceTile.setyPos(entranceTile.getyPos() - ENTRANCETILEOFFSET);
		break;
	case RIGHT:
		entranceTile.setxPos(entranceTile.getxPos() - ENTRANCETILEOFFSET);
		break;
	case DOWN:
		entranceTile.setyPos(entranceTile.getyPos() + ENTRANCETILEOFFSET);
		break;
	case LEFT:
		entranceTile.setxPos(entranceTile.getxPos() + ENTRANCETILEOFFSET);
		break;
	}

	// set tile

	entranceTile.setIsSet(true);

}

bool GameWorld::isOutOfLevel(float xUse, float yUse)						// returns true if an enemy is out of level
									// which is defined as being further than
									// levelWidth or levelHeight divided by 2
									// plus offset
									//		this distance is greater than the one they
									// spawn at
{
	if(abs(xUse) > levelWidth * 0.5 + ENTRANCETILEOFFSET)
	{
		// it's outside
		return true;
	}
	else if(abs(yUse) > levelHeight * 0.5 + ENTRANCETILEOFFSET)
	{
		// it's outside
		return true;
	}
	return false;
}

bool GameWorld::incrementDirTileDir(int xIndex, int yIndex)	// increments dirtile direction
										//	but also makes sure it doesn't result in an
										// infinite loop(tile pointing at previously used tile,
										// incrementing the direction several times if need be,
										// returns false if no direction found
{
	// QUESTION: do we want to somehow indicate tiles that we bump into a second time to help the user?

	// keep incrementing direction until we find something that doesn't have a conflict,
	//	which MAY be the direction we started with!

	bool collision = true;	// if this is false, we've found a valid direction
	bool keepMoving, firstMove;

	int currX, currY, currDir;

	do
	{
		// increment direction
		dirTileArray[yIndex][xIndex].incrementDir();

		// clear out collision array

		for(int i = 0; i < rows; ++i)
		{
			for(int j = 0; j < cols; ++j)
			{
				collisionArray[i][j] = false;
			}
		}

		// test for collisions
		// move
		//	this while loop keeps us moving, exits if we collide or leave the array

		keepMoving = true;
		firstMove = true;

		while(keepMoving == true)
		{
			// move
			if(firstMove == false)
			{
				// move as per currDir

				switch(currDir)
				{
				case UP:
					--currY;
					break;
				case RIGHT:
					++currX;
					break;
				case DOWN:
					++currY;
					break;
				case LEFT:
					--currX;
					break;
				}
			}
			else
			{
				// start at first tile
				currX = firstTileX;
				currY = firstTileY;

				// if the first tile is set
				if(dirTileArray[currY][currX].getIsSet() == true)
				{
					// use the direction of that first tile
					currDir = dirTileArray[currY][currX].getDir();
				}
				else
				{
					// else use the direction of the entrance tile
					currDir = entranceTile.getDir();
				}
				firstMove = false;
			}

			// check if I'm still in the array
			if(currX >= 0
				&& currX < cols
				&& currY >= 0
				&& currY < rows)
			{
				// still in

				// check if i'm on an active directional tile OR it's the tile we're checking for directions
				if(dirTileArray[currY][currX].getIsSet() == true
						|| (currY == yIndex && currX == xIndex))
				{
					// check if we've been here before
					if(collisionArray[currY][currX] == true)
					{
						// been here before
						// exit moving loop and increment direction again
						keepMoving = false;
						collision = true;
					}
					else
					{
						// haven't been here before
						// adjust direction, stay in while loop, mark tile
						currDir = dirTileArray[currY][currX].getDir();
						collisionArray[currY][currX] = true;
					}
				}
				else
				{
					//I'm on an empty tile, so do nothing
				}
			}
			else
			{
				// I'm out without colliding!
				keepMoving = false;
				collision = false;
			}
		}

	}while(collision == true);
	// TODO: make algorithm to check valid directions
}

void GameWorld::processInput(Prismatic* game)
{
	// check game state for what to do
	if(true)
	{
		// if we're in a game state that allows for modification for direction tiles

		// set all tiles to non-preview

		for(int i = 0; i < rows; ++i)
		{
			for(int j = 0; j < cols; ++j)
			{
				dirTileArray[i][j].setIsMousedOver(false);
			}
		}

		// set previews

		// get cursor location
		float CursorX = game->mouseXCoord();
		float CursorY = game->mouseYCoord();

		int xInd = -1;
		int yInd = -1;

		// use cursor location for preview data
		if(getRelevantTile(CursorX, CursorY, xInd, yInd))
		{
			// debug
			assert(xInd != -1);
			assert(yInd != -1);

			dirTileArray[yInd][xInd].setIsMousedOver(true);
		}
		else
		{
			// maybe try to preview entrance tile placement?
			if(entranceSet == false)
			{
				// do stuff
				setEntranceTile(CursorX, CursorY);
			}
		}

		// if mouse clicked
		if(gDInput->mouseButtonReleased(1))	// 1 is for right mouse button
		{
			if(entranceSet == true)
			{
				if(getRelevantTile(CursorX, CursorY, xInd, yInd))
				{
					incrementDirTileDir(xInd, yInd);

					//dirTileArray[yInd][xInd].incrementDir();
					// but we need to make this not cause an infinite loop!
				}
			}
		}

		if(gDInput->mouseButtonReleased(0))	// 0 is for left mouse button
		{
			// first mouse button clicked

			// check to see if we're over a tile
			if(getRelevantTile(CursorX, CursorY, xInd, yInd))
			{
				// if so, we're setting that tile if it has a direction and isn't set
				if(dirTileArray[yInd][xInd].getIsSet() == false)
				{
					if(dirTileArray[yInd][xInd].getDir() != NODIRECTION)
					{
						dirTileArray[yInd][xInd].setIsSet(true);
					}
				}
				else
				{
					// this will unset a true tile...
					dirTileArray[yInd][xInd].setIsSet(false);
				}
			}
			else
			{
				// we're not over a tile, so maybe we're setting an entrance tile?
				if(entranceSet == false)
				{
					// do stuff
					entranceSet = true;
				}
			}
		}
	}
	else if(false)
	{
		// if we're in a game set to set the entrance tile...
	}
	else
	{
		// otherwise we're in another game state
	}
}
